package controller

import (
	"fx_swift_ifcgate_agent/api"
	"fx_swift_ifcgate_agent/internal/service"
	"fx_swift_ifcgate_agent/pkg/code"
	"fx_swift_ifcgate_agent/pkg/internalerrors"
	"github.com/gin-gonic/gin"
	"net/http"
)

// 收款趋势
func CollectTrends(c *gin.Context) {
	req := &api.CollectTrendsReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.Error())
		return
	}
	result, err := service.NewIndexSrv().CollectTrends(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 付款趋势
func PayTrends(c *gin.Context) {
	req := &api.PayTrendsReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.Error())
		return
	}
	result, err := service.NewIndexSrv().PayTrends(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 商户账户总金额
func MerchantAccount(c *gin.Context) {
	result, err := service.NewIndexSrv().MerchantAccount(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 交易总金额
func TotalTransactionAmount(c *gin.Context) {
	result, err := service.NewIndexSrv().TotalTransactionAmount(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 分佣金额
func TotalCommission(c *gin.Context) {
	result, err := service.NewIndexSrv().TotalCommission(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 获取公告
func GetPlacard(c *gin.Context) {
	result, err := service.NewIndexSrv().GetPlacard(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}
